<?php

function getSmarty($app = 'home')
{
    static $smarty = null;
    if (null === $smarty) {
        require_once 'Smarty2/Smarty.class.php';
        $smarty = new Smarty();
        $smarty->left_delimiter = '{=';
        $smarty->right_delimiter = '=}';
        $smarty->setTemplateDir(ROOT_PATH .'/'. $app .'/templates');
        $smarty->setCompileDir(ROOT_PATH .'/'. $app .'/tpl_c');
        $smarty->assign('root', 'http://'.$_SERVER['HTTP_HOST']);
        $smarty->assign('static', '/static');
    }
    return $smarty;
}

function getDb()
{
    if (!Registry::isRegisted('db')) {
        Registry::set('db', new \SF\Db\Db(Config::get('db')));
    }
    return Registry::get('db');
}

function alert($msg)
{
    echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <script type="text/javascript">alert("' . $msg . '");history.go(-1);</script>';
    exit;
}


function p($var)
{
    echo '<pre>';
    print_r($var);
    exit;
}